package com.tuling.JUC;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @Type CountDownLatchUtil.java
 * @Desc 程序减法计数器
 *  当所有的线程都执行完之后countDownLatch =0 的时候执行await 后面操作
 * @Author wzw
 * @Date 2024/9/10 14:14
 */
public class CountDownLatchUtil {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(7);

        System.out.println("33");
        for (int i = 0; i <7 ; i++) {
            new Thread(()->{
                System.out.println("xxxx");
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                countDownLatch.countDown();
                System.out.println("ccc");
            }).start();
        }
        countDownLatch.await();
        System.out.println("执行完成");
    }


}
